#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

static void* (*real_malloc)(size_t) = NULL;
static void (*real_free)(void *) = NULL;
static void (*real_exit)(int) = NULL;

#if 0 /* segfaults */
void *
malloc(size_t size)
{
	real_malloc = dlsym(RTLD_NEXT, "malloc");
	return real_malloc(size);
}
#endif

void
free(void *ptr)
{
	real_free = dlsym(RTLD_NEXT, "free");
	printf("free(%x)\n", ptr);
	real_free(ptr);
}

void
exit(int status)
{
	real_exit = dlsym(RTLD_NEXT, "exit");
	printf("exit(%d)\n", status);
	real_exit(status);
}
